// Ionic Starter App

// angular.module is a global place for creating, registering and retrieving Angular modules
// 'starter' is the name of this angular module example (also set in a <body> attribute in index.html)
// the 2nd parameter is an array of 'requires'
var app = angular.module('myApp', ['ionic']);

app.run(function($ionicPlatform) {
  $ionicPlatform.ready(function() {
    if(window.cordova && window.cordova.plugins.Keyboard) {
      // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
      // for form inputs)
      cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);

      // Don't remove this line unless you know what you are doing. It stops the viewport
      // from snapping when text inputs are focused. Ionic handles this internally for
      // a much nicer keyboard experience.
      cordova.plugins.Keyboard.disableScroll(true);
    }
    if(window.StatusBar) {
      StatusBar.styleDefault();
    }
  });
})
app.controller('myController', function($scope,$ionicPopup,$timeout,$http,$ionicScrollDelegate,$ionicTabsDelegate,$ionicSideMenuDelegate){
  $scope.showPopup = function(){
    $scope.data={};
    var myPopup = $ionicPopup.show({
      template:'<input type="password" ng-model="data.wifi">',
      title:'进入wifi',
      subTitle:'请正常操作',
      scope:$scope,
      buttons:[
        {text:'取消'},
        {
          text:'<b>保存</b>',
          type:'button-positive',
          onTap:function(e){
            if(!$scope.data.wifi){
              e.preventDefault();
            }else{
              return $scope.data.wifi;
            }
          }
        }
      ]
    });
    myPopup.then(function(){
      console.log("tapped!",res)
    });
    // $timeout(function(){
    //   myPopup.close();
    // },3000)
  }

  $scope.showConfirm = function(){
    var confirmPopup = $ionicPopup.confirm({
      title:'删除',
      template:'你确定要删除吗',
      buttons:[
        {text:'取消'},
        {
          text:'确定',
          type:'button-dark'
        }
      ]
    });
    confirmPopup.then(function(res){
      if(res){
        console.log("你确定了")
      }else{
        console.log("你没确定")
      }

    })
  }

  $scope.showAlert = function($cordovaActionSheet){
    var alertPopup = $ionicPopup.alert({
      title:'提示',
      template:'你已经选择过了',
      buttons:[
        {
          text:'确定',
          type:'button-calm'
        }
      ]
    })
    alertPopup.then(function(){
      console.log("你选择了确定")
    })
     // var options = {
     //    title: '你要做什么?',
     //    buttonLabels: ['分享到新浪微博', '分享到朋友圈'],
     //    addCancelButtonWithLabel: '取消',
     //    androidEnableCancelButton: true,
     //    winphoneEnableCancelButton: true,
     //    addDestructiveButtonWithLabel: '删除这个'
     //  };

     //  document.addEventListener("deviceready", function () {

     //    $cordovaActionSheet.show(options)
     //      .then(function(btnIndex) {
     //        var index = btnIndex;
     //      });
     //  }, false);

  }

  // $scope.items = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18];
  // $scope.doRefresh = function(){
  //   $http.get('/new-item')
  //   .success(function(data){
  //     $scope.items = data;
  //   })
  //   .finally(function(){
  //     $scope.$broadcast("更新完成！");
  //   });
  // };
  // $scope.scrollTop = function(){
  //   $ionicScrollDelegate.$getByHandle("mainScroll").scrollTop();
  // };//滚动到头部
  // $scope.scrollSmallTop = function(){
  //   $ionicScrollDelegate.$getByHandle("small").scrollTop();
  // };//小范围滚动到头部
  // $scope.scrollIT = function(){
  //   $ionicScrollDelegate.scrollBottom();
  // };//滚动到底部

  // $scope.selectTabWithIndex = function(index){
  //   $ionicTabsDelegate.select(index);
  // };
  // $scope.toggleLeft = function() {
  //   $ionicSideMenuDelegate.toggleLeft();
  // };
  // $scope.toggleLeftSideMenu = function(){
  //   $ionicSideMenuDelegate.toggleLeft();
  // }
  // $scope.devList = [
  //   { text: "HTML5", checked: true },
  //   { text: "CSS3", checked: false },
  //   { text: "JavaScript", checked: false }
  // ];
  //  $scope.pushNotificationChange = function() {
  //   console.log('Push Notification Change', $scope.pushNotification.checked);
  // };
  
  // $scope.pushNotification = { checked: true };
  // $scope.emailNotification = 'Subscribed';
});
// app.config(function($stateProvider){
//   $stateProvider
//   .state('tab', {
//     url: '/tab',
//     abstract: true,
//     templateUrl: 'templates/home.html'
//   })

// })